import EngineView from "../../engine/EngineView";
import BaseModel from "./BaseModel";
import BaseController from "./BaseController";
import EventProxy from "../event/EventProxy";
import UIManager from "../ui/UIManager";
import PoolInterface from "../pool/PoolInterface";

export default class BaseView extends EngineView implements PoolInterface {



    protected model: any;

    protected controller: any;

    protected eventProxy: EventProxy = new EventProxy();

    setModel(m: BaseModel) {
        this.eventProxy.offAll()
        if (this.model != m) {
            this.model = m;
            this.eventProxy.setDispatcher(this.model)
            this.addListener()
        }
    }

    getModel(){
        return this.model;
    }

    setController(c: BaseController) {
        this.controller = c;
    }


    kill(): void {

    }


    onDestroy() {
        this.eventProxy.offAll()
    }


    addListener() {

    }

    show() {
        UIManager.instance().pushView(this)
    }

    hide(){
        UIManager.instance().popView(this)
    }

    close() {
        this.hide()
    }

}
